package com.contory.ssn_lgnd.app.maingame;

import java.util.LinkedList;
import java.util.Random;

import android.util.Log;

import com.contory.ssn_lgnd.app.comp.DrawPtr;
import com.contory.ssn_lgnd.app.comp.UpdatePtr;
import com.contory.ssn_lgnd.framework.Pool;
import com.contory.ssn_lgnd.framework.Pool.PoolObjectFactory;
import com.contory.ssn_lgnd.framework.gl.SpriteBatcher;

public class ParticleEffectGroup implements DrawPtr, UpdatePtr{
	LinkedList<ParticleEffect> effectList;
	Pool<ParticleEffect> pool;
	final Random rand;
	
	public ParticleEffectGroup(Random rand){
		effectList = new LinkedList<ParticleEffect>();
		this.rand = rand;
		PoolObjectFactory<ParticleEffect> factory = new PoolObjectFactory<ParticleEffect>() {
			@Override
			public ParticleEffect createObject() {
				return new ParticleEffect();
			}
		};
		pool = new Pool<ParticleEffect>(factory, 100);
	}
	
	public ParticleEffect addEffect(){
		ParticleEffect chd = pool.newObject();
		chd.setRandom(rand);
		effectList.add(chd);
		return chd;
	}
	
	@Override
	public void update(float deltaTime) {
		for(int i = 0; i < effectList.size(); i++){
			ParticleEffect effectChd = effectList.get(i);
			effectChd.update(deltaTime);
			if(!effectChd.enableBool){
				pool.free(effectChd);
				effectList.remove(effectChd);
			}
		}
	}

	@Override
	public void draw(SpriteBatcher batcher) {
		for(int i = 0; i < effectList.size(); i++){
			effectList.get(i).draw(batcher);
		}
	}
}
